package com.ag.hmk.action;

import java.util.List;

import com.ag.bean.TbAidgoogs;
import com.ag.common.BaseAction;
import com.ag.common.IDUtil;
import com.ag.hmk.service.impl.HmkUiltServImpl;

/**
 * 
 * @author hmk 查询某一物资库中的某一物资
 */
public class FindOneGoodsAction extends BaseAction {

	private static final long serialVersionUID = 123L;

	private HmkUiltServImpl hmkUiltServImpl;
	private String agkuID1; // 物资库ID
	private String goodsID1; // 物资ID

	private TbAidgoogs aidgooosRST;

	/*
	 * 查询某一物资库中的某一物资
	 */
	public String findOneGoods() throws Exception {
		TbAidgoogs ag = null;
		try {
			String hql = "from TbAidgoogs ag left join fetch ag.tbGoodsstatus left join fetch ag.tbAidgoodsku akgu "
					+ " left join fetch ag.tbGoods g left join fetch g.tbUnit where 1=1 ";
			if (agkuID1 != null && agkuID1.length() > 0 && goodsID1 != null
					&& goodsID1.length() > 0) {
				hql += " and ag.tbAidgoodsku.aidId=" + agkuID1;
				hql += " and ag.tbGoods.goodsId=" + goodsID1;
				hql += " and ag.a='" + IDUtil.PRESERVE + "' ";
				List list = hmkUiltServImpl.hqlQuery(hql);
				if (list != null) {
					ag = (TbAidgoogs) list.iterator().next();
					System.out.println("-------"
							+ ag.getTbGoods().getTbUnit().getUnitName());
				}
			} else {
				System.out.println("------五库ID和物品ID不能为空---");
			}
		} catch (Exception e) {
			e.printStackTrace();
			ag = null;
		}

		this.setAidgooosRST(ag);
		return "findOneGoodsOK";
	}

	public TbAidgoogs getAidgooosRST() {
		return aidgooosRST;
	}

	public void setAidgooosRST(TbAidgoogs aidgooosRST) {
		this.aidgooosRST = aidgooosRST;
	}

	public void setHmkUiltServImpl(HmkUiltServImpl hmkUiltServImpl) {
		this.hmkUiltServImpl = hmkUiltServImpl;
	}

	public void setAgkuID1(String agkuID1) {
		this.agkuID1 = agkuID1;
	}

	public void setGoodsID1(String goodsID1) {
		this.goodsID1 = goodsID1;
	}

}
